package xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.command;

import xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.Editor;
import xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.History;
import xing.design.pattern.behavioral.Memento.sample3_andCommandPattern.editor.command.edit.EditCommand;

/**
 * 反撤销类，不属于编辑类，。所以不继承 {@link EditCommand EditCommand}
 *
 * @author xing
 * @date 2023/2/10 16:02:09
 */
public class RedoCommand implements ICommand {

    /**
     * 对于 Undo 和 Redo ，不保存到 History ，所以这里重写 execute 方法
     */
    @Override
    public void execute(Editor editor) {
        History history = editor.getHistory();
        EditCommand command = history.redoPop();
        if (command == null) {
            return;
        }
        command.execute(editor);
    }


    @Override
    public String getName() {
        return "redo";
    }

}
